<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<link rel="stylesheet" href="../static/css/base.css">
	<script src="../static/js/$_ajax.js"></script>
</head>
<body>
	<div class="login-wrap">
		<p>登录</p>
		<label for="">
			<input type="text" placeholder="请输入用户名" name="username"/>
		</label>
		<label for="">
			<input type="password" placeholder="请输入密码" name="password"/>
		</label>
		<input type="button" value="登录" id="sign-btn"/>
	</div>

	<script>
		var username = document.getElementsByName("username")[0];
		var password = document.getElementsByName("password")[0];
		var sign_btn = document.getElementById("sign-btn");

		sign_btn.addEventListener("click",function(){
			var name = username.value;
			var pw = password.value;

			if(name!=""&&pw!=""){
				$_Ajax({
					url:"http://localhost/ajaxDemo/controller/login.php",
					type:"GET",
					data:{
						username:name,
						password:pw
					},
					asyns:true,
					success:function(results){
						if(results=="1"){
							alert("登录成功");
							location.href = "index.html"
						}else{
							alert("用户名或密码错误")
						}
					},
					error:function(e){
						console.log(e)
					}
				});
			}else{
				alert("用户名或密码不能为空！");				
			}
		});
	</script>
</body>
</html>